<template>
  <el-dropdown trigger="click" @command="selectLang">
    <span class="el-dropdown-link">
      {{ title }}<i class="el-icon-arrow-down el-icon--right"></i>
    </span>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item
        v-for="(value, key) in localList"
        :command="key"
        :key="`lang-${key}`"
        >{{ value }}</el-dropdown-item
      >
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  name: "Language",
  props: {
    lang: String,
  },
  data() {
    return {
      langList: {
        "zh-CN": "语言",
        "zh-TW": "語言",
        "en-US": "Lang",
      },
      localList: {
        "zh-CN": "中文简体",
        "zh-TW": "中文繁体",
        "en-US": "English",
      },
    };
  },
  computed: {
    title() {
      // return this.langList[this.lang]
      return this.localList[this.lang];
    },
  },
  methods: {
    selectLang(name) {
      this.$emit("on-lang-change", name);
    },
  },
};
</script>
<style lang="scss" scoped>
.el-dropdown {
  vertical-align: text-bottom;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
  user-select: none;
}
.el-icon-arrow-down {
  font-size: 12px;
}
</style>
